package com.pojo;
/**
 *
 **/

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;

/**
 * @Author weiwei
 * @Date 2020-11-19 21:09
 * @description 异常地方
 **/
public class ParentAndChildMain {

    public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
        Parent parent=new Parent();
        parent.setName("a");
        parent.setValue("a");
        Child child=new Child(parent);
        System.out.println(JSON.toJSONString(child));
    }

    @Data
    public static class Parent {
        private String name;


        private String value;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    @Data
    public static class Child {
        private String name;

        private String cName;

        private String value;



        public Child(){

        }

        public Child(Parent parent) throws InvocationTargetException, IllegalAccessException {
            org.apache.commons.beanutils.BeanUtils.copyProperties(this,parent);
            //BeanUtils.copyProperties(parent,this);
            cName = "11";
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }
}
